package cn.tedu.myweb.mapper;


import cn.tedu.myweb.entity.FileList;
import cn.tedu.myweb.model.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface FileListMapper {

    @Select("select f.fid,f.fname fname,f.type,f.size,f.status,up_time upTime,r.down_times downTimes,quantity,f2.fname ffname,path,u.nick upNick,r.up_uid upUid from file f left join resources r on f.rid=r.rid left join user u on r.up_uid=u.id left join file f2 on f.ffid=f2.fid where f.ffid is null and f.did=#{did}")
    List<FileList> selectFileListByDid(Integer did);

    @Select("select f.fid,f.fname fname,f.type,f.size,f.status,up_time upTime,r.down_times downTimes,quantity,f2.fname ffname,path,u.nick upNick,r.up_uid upUid from file f left join resources r on f.rid=r.rid left join user u on r.up_uid=u.id left join file f2 on f.ffid=f2.fid where f.ffid is null and f.status=2")
    List<FileList> selectPubFileList(User user);

    @Update("update resources set down_times=down_times+1 where rid=(select rid from file where fid = #{fid})")
    void download(Integer fid);
}
